package org.light.generator;

import java.util.ArrayList;
import java.util.List;

import org.javaforever.gatescore.utils.StringUtil;
import org.light.core.Writeable;
import org.light.domain.Statement;
import org.light.domain.Util;
import org.light.utils.WriteableUtil;

public class EncrptUtilGenerator extends Util{
	public EncrptUtilGenerator(){
		super();
		super.fileName = "EncrptUtil.go";
	}
	
	public EncrptUtilGenerator(String packageToken){
		super();
		this.setPackageToken(packageToken);
		super.fileName = "EncrptUtil.go";
	}
	
	public String getPackageTokenWithDot() {
		if (StringUtil.isBlank(this.getPackageToken())) return "";
		else return this.getPackageToken()+".";
	}
	
	@Override
	public void setPackageToken(String packageToken) {
		this.packageToken = packageToken;
	}
	
	@Override
	public String generateUtilString() {
		List<Writeable> sList = new ArrayList<Writeable>();
		sList.add(new Statement(1000L,0,"package "+this.getPackageTokenWithDot()+"utils"));
		sList.add(new Statement(2000L,0,""));
		
		sList.add(new Statement(2100L,0,"import ("));
		sList.add(new Statement(2200L,1,"\"crypto/md5\""));
		sList.add(new Statement(2300L,1,"\"crypto/sha1\""));
		sList.add(new Statement(2400L,1,"\"fmt\""));
		sList.add(new Statement(2500L,1,"\"io\""));
		sList.add(new Statement(2600L,0,")"));
		
		sList.add(new Statement(3000L,0,"func Sha1Hash(data string) string {"));
		sList.add(new Statement(4000L,1,"t := sha1.New()"));
		sList.add(new Statement(5000L,1,"io.WriteString(t, data)"));
		sList.add(new Statement(6000L,1,"return fmt.Sprintf(\"%x\", t.Sum(nil))"));
		sList.add(new Statement(7000L,0,"}"));
		
		sList.add(new Statement(8000L,0,"func Md5Hash(data string) string {"));
		sList.add(new Statement(9000L,1,"t := md5.New()"));
		sList.add(new Statement(10000L,1,"io.WriteString(t, data)"));
		sList.add(new Statement(11000L,1,"return fmt.Sprintf(\"%x\", t.Sum(nil))"));
		sList.add(new Statement(12000L,0,"}"));

		return WriteableUtil.merge(sList).getContent();
	}

}
